import { Component, OnInit } from '@angular/core';
import {News} from '../../model/News';
import {NewsService} from '../../services/news.service';
import {ActivatedRoute} from '@angular/router';

@Component({
  selector: 'app-newsdetail',
  templateUrl: './newsdetail.component.html',
  styleUrls: ['./newsdetail.component.css']
})
export class NewsdetailComponent implements OnInit {
  n: News;

  constructor(private newsservice: NewsService
  ,private parm :ActivatedRoute

  ) {
    let idparm=parm.snapshot.paramMap.get("newsid");
    this.n=new News();
    this.loadNews(idparm);

  }

  ngOnInit(): void {
  }

  loadNews(id: string) {
    this.newsservice.getNews(id)
      .then((data: any) => {
       this.n=new News();
       if(data.msg='ok'){
         this.n=data.obj;
       }
       else {
         //弹出错误提示

       }
      })

  }
}
